<script>
import _ from 'lodash'
import dataObjectConf from '../data-object-conf.js'
import { getUiItemDataObject, generateOperateButtons, buttonAssociationHandler, getIdentificationDataObject } from '../mixins.js'

const getInputDataObject = (setting = {}, editable, context) => {
  let event = setting.options.event
  return _.merge({}, dataObjectConf, {
    props: {
      placeholder: setting.options.placeholder,
      value: setting.options.defaultValue
    },
    on: {
      'on-change': () => {
        for(let i = 0; i < event.length; i++){
          if(event[i].value[1].value === 'on-change'){
            console.log('执行on-change')
            // buttonAssociationHandler(context,event[i])
          }
        }
      },
      'on-enter': () => {
        for(let i = 0; i < event.length; i++){
          if(event[i].value[1].value === 'on-enter'){
            console.log('执行on-enter')
            // buttonAssociationHandler(context,event[i])
          }
        }
      },
      'on-blur': () => {
        for(let i = 0; i < event.length; i++){
          if(event[i].value[1].value === 'on-blur'){
            console.log('执行on-blur')
            // buttonAssociationHandler(context,event[i])
          }
        }
      },
    }
    // nativeOn: {toBeTriggered: () => { console.log('input事件') }}
  })
}

export default {
  name: 'InputAdapter',
  props: [
    'setting',
    'editable',
    'markSelect',
    'selected'
  ],
  functional: true,
  render (h, context) {
    const editable = context.props.editable
    const markSelect = context.props.markSelect
    const extra = editable ? generateOperateButtons(h, context) : []
    const mark = markSelect ? getIdentificationDataObject(h, context) : []
    return h('FormItem', getUiItemDataObject(context), [
      ...mark,
      h('Input', getInputDataObject(context.props.setting, editable, context)),
      ...extra
    ])
  }
}
</script>
